package ar.edu.unsam.algo3.plantasvszombies.ui.windows

import ar.edu.unsam.algo3.plantasvszombies.dominio.Fila
import ar.edu.unsam.algo3.plantasvszombies.dominio.Zombie
import ar.edu.unsam.algo3.plantasvszombies.ui.ApplicationModels.BatallaAppModel
import org.uqbar.arena.bindings.NotNullObservable
import org.uqbar.arena.bindings.ObservableProperty
import org.uqbar.arena.layout.ColumnLayout
import org.uqbar.arena.widgets.Button
import org.uqbar.arena.widgets.List
import org.uqbar.arena.widgets.Panel
import org.uqbar.arena.widgets.tables.Column
import org.uqbar.arena.widgets.tables.Table
import org.uqbar.arena.windows.MessageBox
import org.uqbar.arena.windows.SimpleWindow
import org.uqbar.arena.windows.WindowOwner

class BatallaWindow extends SimpleWindow<BatallaAppModel> {

	new(WindowOwner parent, Fila fila) {
		super(parent, new BatallaAppModel)
		modelObject.mostrar()
		modelObject.batalla.fila = fila
	}

	override def createMainTemplate(Panel mainPanel) {
		title = "Batalla"
		taskDescription = "Seleccione el zombie atacante"
		super.createMainTemplate(mainPanel)
		this.createResultsGrid(mainPanel)
		var salida = new List(mainPanel)
		salida.setHeigth(200)
		salida.bindItems(new ObservableProperty(modelObject, "resultado"))
	}

	override showError(String message) {
		showMessageBox(MessageBox.Type.Error, message)
	}

	override protected addActions(Panel actionsPanel) {
		new Button(actionsPanel).setCaption("Atacar").onClick[|modelObject.atacar].bindEnabled(
			new NotNullObservable("selectedItem"))
	}

	override protected createFormPanel(Panel mainPanel) {
		var searchFormPanel = new Panel(mainPanel)
		searchFormPanel.setLayout(new ColumnLayout(2))
	}

	def protected createResultsGrid(Panel mainPanel) {
		var table = new Table<Zombie>(mainPanel, typeof(Zombie))
		table.heigth = 100
		table.width = 200
		table.bindItemsToProperty("result")
		table.bindValueToProperty("selectedItem")
		this.describeResultsGrid(table)
	}

	def void describeResultsGrid(Table<Zombie> table) {
		new Column<Zombie>(table) //
		.setTitle("Nombre").setFixedSize(150).bindContentsToProperty("nombre")
	}
}
